package com.jnu.hospitalexamination.controller;

import com.jnu.hospitalexamination.common.Result;
import com.jnu.hospitalexamination.entity.Doctor;
import com.jnu.hospitalexamination.mapper.DoctorMapper;
import com.jnu.hospitalexamination.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @RequestMapping("/list")
    public Result getDoctorList() {
        return Result.success(200, "查询成功", doctorService.list());

    }
//    医生登录

    /**
     * 医生登录
     * @param docId
     * @param password
     * @return
     */
    @RequestMapping("/login")
    public Result login(Integer docId, String password) {
        Doctor doctor = doctorService.getById(docId);
        if (doctor != null && doctor.getPassword().equals(password)) {
            return Result.success(200, "登录成功", doctor);
        } else if (doctor == null){
            return Result.error(400, "用户账号为空", null);
        } else {
            return Result.error(400, "密码错误", null);
        }
    }
}
